import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { VoterComponent } from '../../../templates/componentInteractive/by-eventEmitter';

/**
 * Generated class for the ComponentInteractiveTakerPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-component-interactive-taker',
  templateUrl: 'component-interactive-taker.html',
})
export class ComponentInteractiveTakerPage {
  agreed = 0;
  disagreed = 0;
  voters = ['Mr. IQ', 'Ms. Universe', 'Bombasto'];

  @ViewChild(VoterComponent)
  private voter: VoterComponent;
  private childrenVar2: string;

  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }

  ionViewDidLoad() {

  }

  ngAfterViewInit() {
    this.childrenVar2 = this.voter.var2
    // Redefine `seconds()` to get from the `CountdownTimerComponent.seconds` ...
    // but wait a tick first to avoid one-time devMode
    // unidirectional-data-flow-violation error
    setTimeout(() => {
      // this.childrenVar2 = this.voter.var2
    }, 0);
  }

  onVoted(agreed: boolean) {
    agreed ? this.agreed++ : this.disagreed++;
  }

}
